var _childbar = _interopRequireDefault(require("../navigation-childbar/childbar"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var siteData, isNewUser, _global = global, api = _global.api, util = _global.util, config = _global.config, user = _global.user, app = getApp(), appData = app.globalData, blackArr = [ "black", "#000000", "#000" ], whiteArr = [ "white", "#ffffff", "#fff", "#fafafa", "transparent", "#f4f4f4" ], tabList = {
    card: {
        type: "card",
        name: "名片",
        route: function(t) {
            var a = t.__miniwebquery || {};
            a.cardid ? (this.$report("card_nav_tap"), this.$route("/pages/card/view/view?cardid=".concat(a.cardid, "&guid=").concat(a.guid, "&aid=").concat(a.aid || ""), "redirect")) : this.$route("/pages/tabbar/card/card", "tab");
        },
        url: "https://img.ibos.cn/common/minicard/tab/sitetab/0_v1.png",
        url_active: "https://img.ibos.cn/common/minicard/tab/sitetab/0_v1_active.png"
    },
    site: {
        type: "site",
        name: "官网",
        route: function(t) {
            var a = t.__miniwebquery || {}, e = t.data, i = e.selfCard, s = e.card, r = i.cardid === s.cardid && !i.isMember;
            a.sid ? (this.$report("card_site_tap"), this.$app.recordCount(a.cardid, "site"), 
            this.$route("/miniweb/pages/website/index/index", {
                cardid: a.cardid,
                sid: a.sid,
                guid: a.guid,
                fromuid: a.fromuid,
                source: config.WX_APP_NAME
            }, "redirect")) : r ? this.$route("/pages/contacts/bind/bind") : wx.showModal({
                content: "该用户暂未绑定官网",
                showCancel: !1
            });
        },
        url: "https://img.ibos.cn/common/minicard/tab/sitetab/1_v1.png",
        url_active: "https://img.ibos.cn/common/minicard/tab/sitetab/1_v1_active.png"
    }
};

Component({
    behaviors: [ _childbar.default ],
    options: {
        multipleSlots: !0
    },
    externalClasses: [ "custom-text-color" ],
    properties: {
        title: {
            type: String,
            value: "小名片"
        },
        type: {
            type: String,
            value: "default",
            observer: function(t) {
                switch (t) {
                  case "view":
                  case "site":
                    var a = {
                        showTitle: !1
                    };
                    return "site" === t && siteData && (a.tabs = siteData, a.tabActive = "site"), void this.setData(a);

                  case "tab":
                    this.setData({
                        showBack: !1
                    });

                  default:
                    siteData = void 0;
                }
            }
        },
        backProxy: {
            type: Boolean,
            value: !1
        },
        backListen: {
            type: Boolean,
            value: !1
        },
        background: {
            type: String,
            value: "#ffffff",
            observer: function(t) {
                var a = {
                    iconName: "white",
                    textStyle: "white"
                };
                blackArr.includes(t) ? a.textStyle = "white" : whiteArr.includes(t) && (a.textStyle = "black", 
                a.iconName = ""), this.setData(a);
            }
        },
        textStyle: {
            type: String,
            value: "black"
        },
        showNav: {
            type: Boolean,
            value: !0
        },
        showTitle: {
            type: Boolean,
            value: !0
        },
        card: {
            type: Object,
            value: {},
            observer: function() {
                var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {};
                t && t.cardid && (+global.user.getTokensSync().uid == +t.uid || +t.sid ? this.initSite(t.guid, t.sid) : this.setData({
                    type: "default",
                    showTitle: !0
                }));
            }
        }
    },
    data: {
        hideNavBox: !1,
        showBack: !0,
        iconName: "",
        tabActive: "card"
    },
    attached: function() {
        var BAR_HEIGHT = appData.BAR_HEIGHT, NAVBAR_HEIGHT = appData.NAVBAR_HEIGHT, e = BAR_HEIGHT + (this.data.showNav ? NAVBAR_HEIGHT : 0) + "px";
        this.setData({
            NAVBAR_HEIGHT: NAVBAR_HEIGHT,
            BAR_HEIGHT: BAR_HEIGHT,
            holderHeight: e
        });
    },
    ready: function() {
        this.setPage(), this.setBackText(), this.setPageNavH(), this.shareHook(), "site" === this.data.type && this.initSite();
    },
    methods: {
        setPage: function() {
            var t = this.pages = getCurrentPages();
            this.page = t[t.length - 1];
        },
        setBackText: function() {
            if (!("tab" === this.data.type)) {
                var t = this.page.__query, a = "pages/tabcommonlist/tabcommonlist" === this.page.route;
                (1 === this.pages.length && !a || t.mine) && this.setData({
                    backText: "首页"
                });
            }
        },
        setPageNavH: function() {
            this.page.setData({
                BAR_HEIGHT: this.data.holderHeight
            });
        },
        shareHook: function() {
            var r = this.page.onShareAppMessage;
            if (!appData.isIOS && r) {
                var n = this;
                this.page.onShareAppMessage = function() {
                    var t = this, a = this.data.BAR_HEIGHT;
                    n.setData({
                        hideNavBox: !0
                    }), this.setData({
                        BAR_HEIGHT: "0px"
                    }), wx.sleepSync(100), wx.setTimeout(function() {
                        n.setData({
                            hideNavBox: !1
                        }), t.setData({
                            BAR_HEIGHT: a
                        });
                    }, 800);
                    for (var e = arguments.length, i = new Array(e), s = 0; s < e; s++) i[s] = arguments[s];
                    return r.call.apply(r, [ this ].concat(i));
                };
            }
        },
        onTap: function() {
            wx.pageScrollTo({
                scrollTop: 0
            });
        },
        onSwitch: function() {
            var a = this;
            this.$report("switch_card_cut");
            var t = appData.card;
            t.guid ? this.$route("/pages/contacts/switch/switch?guid=".concat(t.guid)) : wx.showModal({
                content: "你还没有名片噢，去创建一张吧",
                success: function(t) {
                    t.confirm && a.$route("/pages/card/create/create");
                }
            });
        },
        onBack: function() {
            this.route(this.onBackHandle.bind(this));
        },
        onBackHandle: function() {
            1 === this.pages.length ? this.$route("/pages/tabbar/card/card", "tab") : this.$route("back");
        },
        onIndex: function() {
            var t = this;
            this.route(function() {
                return t.$route("/pages/tabbar/card/card", "tab");
            });
        },
        route: function(t) {
            var a = this.data, e = a.backProxy, i = a.backListen;
            if (e) return this.triggerEvent("unload", {}, {});
            i && this.triggerEvent("beforeunload", {}, {}), t();
        },
        onNavigate: function(t) {
            var a = t.currentTarget.dataset.type;
            this.data.tabActive !== a && tabList[a].route.call(this, this.page);
        },
        initSite: function(t, a) {
            var e = this;
            return t = t || appData.fromguid, a = a || appData.fromsid, this.setSiteStyle(), 
            api.minicard.sitetab.lists({
                data: {
                    guid: t,
                    sid: a
                }
            }).then(function(t) {
                var a = {};
                t.data && t.data.list && (a = t.data.list.find(function(t) {
                    return t.isdefault;
                }), [ "url", "url_active" ].forEach(function(t) {
                    return a[t] = a[t].replace(/(\d+)/, "$1_v1") + "?v=1";
                })), e.setTab(a);
            }).catch(function() {
                return e.setTab();
            });
        },
        setTab: function() {
            var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {};
            this.page || this.setPage();
            var a = (this.page || {}).route, e = JSON.parse(JSON.stringify(tabList));
            Object.assign(e.site, t);
            var i = /miniweb/.test(a), s = i ? "site" : "card";
            siteData = e, this.newUserMiniwebTip(i), this.setData({
                tabs: e,
                tabActive: s
            });
        },
        newUserMiniwebTip: function(t) {
            if (!t && !isNewUser) {
                var a = appData.card;
                a && a.cardid || (isNewUser = !0, this.setData({
                    webDot: !0
                }));
            }
        }
    }
});